package com.unis.utils

import com.unis.utils.FastJsonUtil.getClass
import net.minidev.json.JSONObject
import net.minidev.json.parser.JSONParser
import org.apache.log4j.Logger
import org.slf4j.{Logger, LoggerFactory}

import scala.collection.mutable

object StringToMap {
  private val logger= LoggerFactory.getLogger(getClass)
  def jsonToMap(json : String) : mutable.HashMap[String,String] = {

    val map : mutable.HashMap[String,String]= mutable.HashMap()
    try{
      val jsonParser =new JSONParser()
      //将string转化为jsonObject
      val jsonObj: JSONObject = jsonParser.parse(json).asInstanceOf[JSONObject]
      //获取所有键
      val jsonKey = jsonObj.keySet()

      val iter = jsonKey.iterator()

      while (iter.hasNext){
        val field = iter.next()
        val value = jsonObj.get(field).toString
        map.put(field.toString,value.toString)
      }
      map

    }catch {
      case e:Exception=>logger.error(" exception.,"+e.toString)
    }
    map

  }

}
